﻿// See https://aka.ms/new-console-template for more information
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;

Console.WriteLine("Hello, World!");

ConnectionFactory factory = new() {
    HostName = "192.168.5.168",
    UserName = "admin",
    Password = "123"
};
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) => {
    var body = ea.Body.ToArray();
    var message = Encoding.UTF8.GetString(body);
    // await Task.Yield();
    //LogWrite("信息", message);
    Console.WriteLine(message);
    channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
};
channel.BasicConsume(queue: "log", autoAck: false, consumer: consumer);



Console.ReadKey();
